		page	60,130
		title	Nintendo Drawing program assembly code module.
		subttl	Copyright (C) 1990 Color Dreams

; Written March 1990 


		.model	medium,c


		.data

		extrn	errno:word
		public	brkkey,cs3x5
		public	mp_arrow,mp_draw,mp_flip,mp_wait,mp_mag,v_bios

VSEG		equ	0A000H
XSIZE		equ	320
YSIZE		equ	200

v_bios		db	0

MQ_SIZE		equ	32			;Entries in mouse event queue.
mq_head		dw	0
mq_tail		dw	0
mq		db	MQ_SIZE dup (6 dup (0))
ms_driver	db	0

mp_arrow	db	0,0
		dw	0000111111111111b
		dw	0000011111111111b
		dw	0000111111111111b
		dw	0000011111111111b
		dw	1010001111111111b
		dw	1111000111111111b
		dw	1111101111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	0000000000000000b
		dw	0111000000000000b
		dw	0110000000000000b
		dw	0101000000000000b
		dw	0000100000000000b
		dw	0000010000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b

mp_draw		db	0,0
		dw	0011111111111111b
		dw	0001111111111111b
		dw	1000111111111111b
		dw	1100011111111111b
		dw	1110001111111111b
		dw	1111000111111111b
		dw	1111101111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	0000000000000000b
		dw	0100000000000000b
		dw	0010000000000000b
		dw	0001000000000000b
		dw	0000100000000000b
		dw	0000010000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b

mp_flip		db	9,4
		dw	1000011111111111b
		dw	0000011111111111b
		dw	1000011111111111b
		dw	0000011110111111b
		dw	0000111100011111b
		dw	0001111110111111b
		dw	0001111111111111b
		dw	0001111111111111b
		dw	1000111111111111b
		dw	1101111111000011b
		dw	1111101110000011b
		dw	1111000000000011b
		dw	1111100000000011b
		dw	1111110000010111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	0000000000000000b
		dw	0111000000000000b
		dw	0011000000000000b
		dw	0101000000000000b
		dw	0100000001000000b
		dw	0100000000000000b
		dw	0100000000000000b
		dw	0100000000000000b
		dw	0010000000000000b
		dw	0000000000000000b
		dw	0000000000111000b
		dw	0000010000011000b
		dw	0000001111101000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b

mp_wait		db	3,5
		dw	1000001111111111b
		dw	0111110111111111b
		dw	0000000111111111b
		dw	1000001111111111b
		dw	1100011111111111b
		dw	1110111111111111b
		dw	1101011111111111b
		dw	1011101111111111b
		dw	0100010111111111b
		dw	0000000111111111b
		dw	1000001111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0111110000000000b
		dw	0011100000000000b
		dw	0001000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0011100000000000b
		dw	0111110000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b

mp_mag		db	4,4
		dw	1110001111111111b
		dw	1100000111111111b
		dw	1001110011111111b
		dw	0011111001111111b
		dw	0011111001111111b
		dw	0011111001111111b
		dw	1001110011111111b
		dw	1100000111111111b
		dw	1110001111111111b
		dw	1110001111111111b
		dw	1110001111111111b
		dw	1110001111111111b
		dw	1110001111111111b
		dw	1111011111111111b
		dw	1111111111111111b
		dw	1111111111111111b
		dw	0000000000000000b
		dw	0001110000000000b
		dw	0010001000000000b
		dw	0100000100000000b
		dw	0100000100000000b
		dw	0100000100000000b
		dw	0010001000000000b
		dw	0001110000000000b
		dw	0000100000000000b
		dw	0000100000000000b
		dw	0000100000000000b
		dw	0000100000000000b
		dw	0000100000000000b
		dw	0000000000000000b
		dw	0000000000000000b
		dw	0000000000000000b

brkkey		db	0

ic_stat		db	0
brkstat		db	0
vec05		dd	0
vec1b		dd	0
vec23		dd	0
vec24		dd	0


; 5 x 7 ASCII character set (20H-5FH):
;
;        Û    Û Û   Û Û    Û   ÛÛ     Û      Û   
;        Û    Û Û   Û Û   ÛÛÛÛ ÛÛ  Û Û Û     Û   
;        Û    Û Û  ÛÛÛÛÛ Û        Û   Û     Û    
;        Û          Û Û   ÛÛÛ    Û   Û Û Û       
;        Û         ÛÛÛÛÛ     Û  Û    Û  Û        
;                   Û Û  ÛÛÛÛ  Û  ÛÛ Û  ÛÛ       
;        Û          Û Û    Û      ÛÛ  ÛÛ         
;
;   Û   Û                                        
;  Û     Û   ÛÛ ÛÛ   Û                         Û 
; Û       Û   ÛÛÛ    Û                        Û  
; Û       Û  ÛÛÛÛÛ ÛÛÛÛÛ       ÛÛÛÛÛ         Û   
; Û       Û   ÛÛÛ    Û     Û                Û    
;  Û     Û   ÛÛ ÛÛ   Û     Û               Û     
;   Û   Û                 Û            Û         
;
; ÛÛÛ    Û    ÛÛÛ   ÛÛÛ     Û  ÛÛÛÛÛ   ÛÛÛ ÛÛÛÛÛ 
;Û   Û  ÛÛ   Û   Û Û   Û   ÛÛ  Û      Û    Û   Û 
;Û  ÛÛ   Û       Û     Û  Û Û  Û     Û         Û 
;Û Û Û   Û     ÛÛ    ÛÛ  Û  Û  ÛÛÛÛ  ÛÛÛÛ     Û  
;ÛÛ  Û   Û    Û        Û ÛÛÛÛÛ     Û Û   Û   Û   
;Û   Û   Û   Û     Û   Û    Û  Û   Û Û   Û   Û   
; ÛÛÛ   ÛÛÛ  ÛÛÛÛÛ  ÛÛÛ    ÛÛÛ  ÛÛÛ   ÛÛÛ    Û   
;
; ÛÛÛ   ÛÛÛ                 Û         Û     ÛÛÛ  
;Û   Û Û   Û   Û     Û     Û           Û   Û   Û 
;Û   Û Û   Û              Û    ÛÛÛÛÛ    Û      Û 
; ÛÛÛ   ÛÛÛÛ             Û               Û    Û  
;Û   Û     Û              Û    ÛÛÛÛÛ    Û    Û   
;Û   Û    Û    Û     Û     Û           Û         
; ÛÛÛ   ÛÛ          Û       Û         Û      Û   
;
;  ÛÛ    Û   ÛÛÛÛ   ÛÛÛ  ÛÛÛÛ  ÛÛÛÛÛ ÛÛÛÛÛ  ÛÛÛ  
; Û  Û  Û Û   Û  Û Û   Û  Û  Û  Û     Û    Û   Û 
;Û ÛÛÛ Û   Û  Û  Û Û      Û  Û  Û     Û    Û     
;Û ÛÛ  Û   Û  ÛÛÛ  Û      Û  Û  ÛÛÛ   ÛÛÛ  Û     
;Û     ÛÛÛÛÛ  Û  Û Û      Û  Û  Û     Û    Û  ÛÛ 
; Û  Û Û   Û  Û  Û Û   Û  Û  Û  Û     Û    Û   Û 
;  ÛÛ  Û   Û ÛÛÛÛ   ÛÛÛ  ÛÛÛÛ  ÛÛÛÛÛ ÛÛÛ    ÛÛÛ  
;
;Û   Û  ÛÛÛ    ÛÛÛ ÛÛ  Û ÛÛÛ   Û   Û Û   Û  ÛÛÛ  
;Û   Û   Û      Û   Û  Û  Û    ÛÛ ÛÛ ÛÛ  Û Û   Û 
;Û   Û   Û      Û   Û Û   Û    ÛÛÛÛÛ ÛÛÛ Û Û   Û 
;ÛÛÛÛÛ   Û      Û   ÛÛ    Û    Û Û Û Û ÛÛÛ Û   Û 
;Û   Û   Û      Û   Û Û   Û    Û   Û Û  ÛÛ Û   Û 
;Û   Û   Û   Û  Û   Û  Û  Û  Û Û   Û Û   Û Û   Û 
;Û   Û  ÛÛÛ   ÛÛ   ÛÛ  Û ÛÛÛÛÛ Û   Û Û   Û  ÛÛÛ  
;
;ÛÛÛÛ   ÛÛÛ  ÛÛÛÛ   ÛÛÛ  ÛÛÛÛÛ Û   Û Û   Û Û   Û 
; Û  Û Û   Û  Û  Û Û   Û Û Û Û Û   Û Û   Û Û   Û 
; Û  Û Û   Û  Û  Û Û       Û   Û   Û Û   Û Û   Û 
; ÛÛÛ  Û   Û  ÛÛÛ   ÛÛÛ    Û   Û   Û Û   Û Û   Û 
; Û    Û Û Û  Û Û      Û   Û   Û   Û ÛÛ ÛÛ Û Û Û 
; Û     ÛÛÛ   Û  Û Û   Û   Û   Û   Û  ÛÛÛ  Û Û Û 
;ÛÛÛ      ÛÛ ÛÛ  Û  ÛÛÛ   ÛÛÛ   ÛÛÛ    Û    Û Û  
;
;Û   Û Û   Û ÛÛÛÛÛ  ÛÛÛ         ÛÛÛ    Û         
;Û   Û Û   Û Û   Û  Û    Û        Û   Û Û        
; Û Û  Û   Û    Û   Û     Û       Û              
;  Û    Û Û    Û    Û      Û      Û              
; Û Û    Û    Û     Û       Û     Û              
;Û   Û   Û   Û   Û  Û        Û    Û              
;Û   Û  ÛÛÛ  ÛÛÛÛÛ  ÛÛÛ         ÛÛÛ        ÛÛÛÛÛ 
;
;ÛÛÛÛÛ 
;ÛÛÛÛÛ 
;ÛÛÛÛÛ 
;ÛÛÛÛÛ 
;ÛÛÛÛÛ 
;ÛÛÛÛÛ 
;ÛÛÛÛÛ 
;

cs5x7		db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	;SP
		db	0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0	;!
		db	0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	;"
		db	0,1,0,1,0,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,0,1,0,1,0	;#
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ÛÛ  ÛÛ Û Û Û   Û   Û   ÛÛÛ ÛÛÛ     ÛÛ   ÛÛ ÛÛÛ Û Û Û Û 
;Û   Û Û  Û    Û Û Û Û   ÛÛ  ÛÛ  Û Û Û Û     Û Û Û    Û  Û Û Û Û 
;Û Û ÛÛÛ  Û    Û ÛÛ  Û   Û Û Û Û Û Û ÛÛÛ     ÛÛ   Û   Û  Û Û Û Û 
;Û   Û Û  Û  Û Û Û Û Û   Û   Û   Û Û Û       Û Û   Û  Û  Û Û Û Û 
; ÛÛ Û Û ÛÛÛ ÛÛÛ Û Û ÛÛÛ Û   Û   ÛÛÛ Û       Û Û ÛÛ   Û  ÛÛÛ  Û  
;
;Û Û Û Û Û Û ÛÛÛ       Û   Û   Û   Û         Û     Û       Û     
;Û Û Û Û Û Û   Û  Û   ÛÛ   Û   Û  ÛÛ         ÛÛ   ÛÛ  Û    Û     
;Û Û  Û   Û   Û        Û   Û   Û ÛÛÛ ÛÛÛ ÛÛÛ ÛÛÛ Û Û   Û Û Û   Û 
;Û Û Û Û  Û  Û    Û    Û   Û   Û  ÛÛ         ÛÛ    Û      ÛÛ  Û  
; Û  Û Û  Û  ÛÛÛ       Û   Û  Û    Û         Û     Û       Û     
;
;  Û       Û ÛÛÛ  ÛÛ   Û     ÛÛÛ 
; ÛÛ  Û        Û      ÛÛ  Û  ÛÛÛ 
;ÛÛÛ  ÛÛ   Û ÛÛÛ  ÛÛ ÛÛÛ  ÛÛ ÛÛÛ 
; ÛÛ  Û    Û  ÛÛ  Û    Û     ÛÛÛ 
;  Û       Û   Û     ÛÛÛ  ÛÛ ÛÛÛ 

cs3x5		db	1,1,1,1,0,1,1,0,1,1,0,1,1,1,1		;0
		db	0,1,0,1,1,0,0,1,0,0,1,0,1,1,1		;1
		db	1,1,1,0,0,1,1,1,1,1,0,0,1,1,1		;2
		db	1,1,1,0,0,1,1,1,1,0,0,1,1,1,1		;3
		db	1,0,1,1,0,1,1,1,1,0,0,1,0,0,1		;4
		db	1,1,1,1,0,0,1,1,1,0,0,1,1,1,1		;5
		db	1,1,1,1,0,0,1,1,1,1,0,1,1,1,1		;6
		db	1,1,1,0,0,1,0,0,1,0,0,1,0,0,1		;7
		db	1,1,1,1,0,1,1,1,1,1,0,1,1,1,1		;8
		db	1,1,1,1,0,1,1,1,1,0,0,1,1,1,1		;9
		db	1,1,1,1,0,1,1,1,1,1,0,1,1,0,1		;A
		db	1,1,0,1,0,1,1,1,0,1,0,1,1,1,0		;B
		db	1,1,1,1,0,0,1,0,0,1,0,0,1,1,1		;C
		db	1,1,0,1,0,1,1,0,1,1,0,1,1,1,0		;D
		db	1,1,1,1,0,0,1,1,0,1,0,0,1,1,1		;E
		db	1,1,1,1,0,0,1,1,0,1,0,0,1,0,0		;F
                db      0,1,1,1,0,0,1,0,1,1,0,0,0,1,1           ;G
                db      1,0,1,1,0,1,1,1,1,1,0,1,1,0,1           ;H
                db      1,1,1,0,1,0,0,1,0,0,1,0,1,1,1           ;I
                db      0,1,1,0,0,1,0,0,1,1,0,1,1,1,1           ;J
                db      1,0,1,1,0,1,1,1,0,1,0,1,1,0,1           ;K
                db      1,0,0,1,0,0,1,0,0,1,0,0,1,1,1           ;L
                db      1,0,0,1,1,0,1,0,1,1,0,0,1,0,0           ;M
                db      1,0,0,1,1,0,1,0,1,1,0,0,1,0,0           ;N
                db      1,1,1,1,0,1,1,0,1,1,0,1,1,1,1           ;O
                db      1,1,1,1,0,1,1,1,1,1,0,0,1,0,0           ;P
                db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0           ;SPACE (Q)
                db      1,1,0,1,0,1,1,1,0,1,0,1,1,0,1           ;R
                db      0,1,1,1,0,0,0,1,0,0,0,1,1,1,0           ;S
                db      1,1,1,0,1,0,0,1,0,0,1,0,0,1,0           ;T
                db      1,0,1,1,0,1,1,0,1,1,0,1,1,1,1           ;U
                db      1,0,1,1,0,1,1,0,1,1,0,1,0,1,0           ;V
                db      1,0,1,1,0,1,1,0,1,1,0,1,0,1,0           ;W
                db      1,0,1,1,0,1,0,1,0,1,0,1,1,0,1           ;X
                db      1,0,1,1,0,1,0,1,0,0,1,0,0,1,0           ;Y
                db      1,1,1,0,0,1,0,1,0,1,0,0,1,1,1           ;Z
                db      0,0,0,0,1,0,0,0,0,0,1,0,0,0,0           ;':'	(36)
                db      0,0,1,0,1,1,0,0,1,0,0,1,0,0,1           ;M2
                db      0,0,1,0,0,1,0,0,1,0,0,1,0,0,1           ;N2
                db      0,0,1,0,0,1,0,0,1,0,0,1,0,1,0           ;W2
                db      0,0,1,0,1,1,1,1,1,0,1,1,0,0,1           ;LEFT	(40)
                db      0,0,0,0,0,0,1,1,1,0,0,0,0,0,0           ;LEFT2
                db      0,0,0,0,0,0,1,1,1,0,0,0,0,0,0           ;RIGHT	(42)
                db      1,0,0,1,1,0,1,1,1,1,1,0,1,0,0           ;RIGHT2
                db      0,0,1,0,1,1,1,0,1,0,0,1,0,0,1           ;UP	(44)
                db      0,0,0,0,1,0,0,0,1,0,0,0,0,0,0           ;UP2
                db      0,0,1,0,0,1,1,0,1,0,1,1,0,0,1           ;DOWN	(46)
                db      0,0,0,0,0,0,0,0,1,0,1,0,0,0,0           ;DOWN2
                db      0,0,1,0,1,1,1,1,1,0,1,1,0,0,1           ;DIAMOND (48)
                db      0,0,0,0,1,0,0,1,1,0,1,0,0,0,0           ;DIAMOND2
                db      0,0,1,0,0,0,0,0,1,0,0,1,0,0,1           ;G2
                db      1,1,1,0,0,1,1,1,1,0,1,1,0,0,1           ;DOWNB	(51)
                db      0,1,1,0,0,0,0,1,1,0,1,0,0,0,0           ;DOWNB2
                db      0,0,1,0,1,1,1,1,1,0,0,1,1,1,1           ;UPB	(53)
                db      0,0,0,0,1,0,0,1,1,0,0,0,0,1,1           ;UPB2
                db      1,1,1,1,1,1,1,1,1,1,1,1,1,1,1           ;UNDEFINED

SPL3X5		equ	37
LAST3X5		equ	55


		.code

		extrn	procmouse:far


;Wait for vertical retrace.
wait_vert	proc	near

		mov	dx,3dah		;Input Status Register One port.
wait0:		in	al,dx
		test	al,00001000b	;Check vertical retrace bit.
		jnz	wait0		;Loop until clear (no retrace).

wait1:		in	al,dx
		test	al,00001000b	;Check vertical retrace bit.
		jz	wait1		;Loop until set (start retrace).

		ret
wait_vert	endp


;Return the video mode.
v_getmode	proc	uses si di
		mov	ah,0fh
		int	10h
		xor	ah,ah		;Video mode is in AL.
		ret
v_getmode	endp


;Set the video mode.
v_setmode	proc	uses si di,mode:byte
		mov	al,mode
		mov	ah,0
		int	10h
		ret
v_setmode	endp


;Set individual VGA palette register (hardware direct).
v_setpal	proc	uses si di,palreg:byte,paldata:ptr byte

		cmp	v_bios,0
		jz	direct		;go if not using BIOS call

		mov	bx,paldata
		mov	dh,[bx]
		inc	bx
		mov	ch,[bx]
		inc	bx
		mov	cl,[bx]
		mov	bl,palreg
		xor	bh,bh
		mov	ax,1010h
		int	10h
		jmp	exit		;continue

direct:		mov	bx,paldata
		mov	dx,3c8h
		mov	al,palreg
		out	dx,al
		mov	al,[bx]
		inc	dx
		out	dx,al
		inc	bx
		mov	al,[bx]
		out	dx,al
		inc	bx
		mov	al,[bx]
		out	dx,al
exit:
		ret
v_setpal	endp


;Set block of VGA palette registers (hardware direct).
v_setpalblk	proc	uses si di,palreg:byte,numreg:word,paldata:ptr byte

		cmp	v_bios,0
		jz	direct		;go if not using BIOS call

		mov	bl,palreg
		xor	bh,bh
		mov	cx,numreg
		mov	dx,paldata
		push	ds
		pop	es
		mov	ax,1012h
		int	10h
		jmp	exit		;continue

direct:		mov	cx,numreg
		mov	bx,paldata
		mov	dx,3c8h
		mov	al,palreg
		out	dx,al
		inc	dx

lp:		mov	al,[bx]
		out	dx,al
		inc	bx
		mov	al,[bx]
		out	dx,al
		inc	bx
		mov	al,[bx]
		out	dx,al
		inc	bx
		loop	lp		;Loop for all registers.
exit:
		ret
v_setpalblk	endp


;Read individual VGA palette register (BIOS call).
v_getpal	proc	uses si di,palreg:word,redval:ptr byte,grnval:ptr byte,bluval:ptr byte

		mov	bx,palreg
		mov	ax,1015h
		int	10h

		mov	bx,redval
		mov	[bx],dh
		mov	bx,grnval
		mov	[bx],ch
		mov	bx,bluval
		mov	[bx],cl

		ret
v_getpal	endp


;Read block of VGA palette registers (BIOS call).
v_getpalblk	proc	uses si di,palreg:word,numreg:word,dptr:far ptr byte

		mov	bx,palreg
		mov	cx,numreg
		les	dx,dptr
		mov	ax,1017h
		int	10h

		ret
v_getpalblk	endp


;Clear the graphics screen (mode 13h only).
v_gcls		proc	uses di,bgcolor:byte
		mov	ax,VSEG
		mov	es,ax
		xor	di,di
		mov	cx,32000
		mov	al,bgcolor
		mov	ah,bgcolor
		rep stosw
		ret
v_gcls		endp


;Draw a horizontal line.
v_hline		proc	uses di,pos:word,xlen:word,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	al,color
		mov	cx,xlen
		rep stosb		;Draw the line.
		
		ret
v_hline		endp


;Draw a vertical line.
v_vline		proc	uses di,pos:word,ylen:word,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	al,color
		mov	cx,ylen
		mov	bx,XSIZE
lp:		mov	es:[di],al
		add	di,bx
		loop	lp		;Draw the line.

		ret
v_vline		endp


;Draw a box (border only).
v_box		proc	uses di,pos:word,xlen:word,ylen:word,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	bx,xlen
		mov	dx,XSIZE
		sub	dx,bx
		mov	al,color

		mov	cx,bx
		rep stosb		;Draw top line.
		add	di,dx

		dec	bx
		inc	dx
		mov	cx,ylen
		sub	cx,2
lp:		mov	es:[di],al	;Set pixel on left.
		add	di,bx
		mov	es:[di],al	;Set pixel on right.
		add	di,dx
		loop	lp
		inc	bx

		mov	cx,bx
		rep stosb		;Draw bottom line.

		ret
v_box		endp


;Draw a solid box (filled).
v_boxf		proc	uses di,pos:word,xlen:word,ylen:word,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	bx,xlen
		mov	dx,XSIZE
		sub	dx,bx
		mov	al,color

		mov	cx,ylen
lp:		push	cx

		mov	cx,bx
		rep stosb		;Draw one line.
		add	di,dx

		pop	cx
		loop	lp		;Repeat for entire box.

		ret
v_boxf		endp


;Draw a selection box (border only - saves video written over).
v_selbox	proc	uses ds si di,saveptr:ptr byte,pos:word,xlen:word,ylen:word,color:byte
		push	ds
		pop	es
		mov	di,saveptr	;Get save buffer pointer.

		mov	ax,VSEG
		mov	ds,ax
		mov	si,pos		;Get starting position (Y*320+X).

		mov	bx,xlen
		mov	dx,XSIZE
		sub	dx,bx
		mov	al,color

		mov	cx,bx
		rep movsb		;Save top line.
		push	es
		push	di

		push	ds
		pop	es
		mov	di,pos		;Get screen offset.
		mov	cx,bx
		rep stosb		;Draw top line.
		add	di,dx

		mov	si,di
		pop	di
		pop	es

		dec	bx
		dec	bx
		mov	cx,ylen
		sub	cx,2

lp:		movsb			;Save screen data.
		mov	[si-1],al	;Set pixel on left.
		add	si,bx
		movsb
		mov	[si-1],al	;Set pixel on right.
		add	si,dx
		loop	lp

		inc	bx
		inc	bx

		push	si
		mov	cx,bx
		rep movsb		;Save bottom line.

		pop	di
		push	ds
		pop	es

		mov	cx,bx
		rep stosb		;Draw bottom line.

		ret
v_selbox	endp


;Draw an animated (4-color cycling) selection box (saves video written over).
v_sel2box	proc	uses ds si di,saveptr:ptr byte,pos:word,xlen:word,ylen:word,color1:byte,color2:byte,color3:byte,color4:byte
		push	ds
		pop	es
		mov	di,saveptr	;Get save buffer pointer.

		mov	ax,VSEG
		mov	ds,ax
		mov	si,pos		;Get starting position (Y*320+X).

		mov	dx,XSIZE
		sub	dx,xlen
		mov	al,color1	;Get colors.
		mov	ah,color2
		mov	bl,color3
		mov	bh,color4

		mov	cx,xlen
		rep movsb		;Save top line.

		mov	si,pos		;Get screen offset.
		mov	cx,xlen
		shr	cx,1
		shr	cx,1
toplp:		mov	[si],al
		inc	si
		mov	[si],ah
		inc	si
		mov	[si],bl
		inc	si
		mov	[si],bh
		inc	si
		loop	toplp		;Draw top line.
		add	si,dx

		mov	cx,ylen
		sub	cx,2
		shr	cx,1
		shr	cx,1

lp:		movsb			;Save screen data.
		mov	[si-1],bh	;Set pixel on left.
		add	si,xlen
		sub	si,2
		movsb
		mov	[si-1],al	;Set pixel on right.
		add	si,dx

		movsb			;Save screen data.
		mov	[si-1],bl	;Set pixel on left.
		add	si,xlen
		sub	si,2
		movsb
		mov	[si-1],ah	;Set pixel on right.
		add	si,dx

		movsb			;Save screen data.
		mov	[si-1],ah	;Set pixel on left.
		add	si,xlen
		sub	si,2
		movsb
		mov	[si-1],bl	;Set pixel on right.
		add	si,dx

		movsb			;Save screen data.
		mov	[si-1],al	;Set pixel on left.
		add	si,xlen
		sub	si,2
		movsb
		mov	[si-1],bh	;Set pixel on right.
		add	si,dx

		loop	lp		;Draw sides.

		movsb			;Save screen data.
		mov	[si-1],bh	;Set pixel on left.
		add	si,xlen
		sub	si,2
		movsb
		mov	[si-1],al	;Set pixel on right.
		add	si,dx

		movsb			;Save screen data.
		mov	[si-1],bl	;Set pixel on left.
		add	si,xlen
		sub	si,2
		movsb
		mov	[si-1],ah	;Set pixel on right.
		add	si,dx

		push	si
		mov	cx,xlen
		rep movsb		;Save bottom line.

		pop	si
		mov	cx,xlen
		shr	cx,1
		shr	cx,1
botlp:		mov	[si],ah
		inc	si
		mov	[si],al
		inc	si
		mov	[si],bh
		inc	si
		mov	[si],bl
		inc	si
		loop	botlp		;Draw top line.

		ret
v_sel2box	endp


;Replace a selection box from the save buffer (border only).
v_undobox	proc	uses ds si di,saveptr:ptr byte,pos:word,xlen:word,ylen:word
		mov	si,saveptr	;Get save buffer pointer.

		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	bx,xlen
		mov	dx,XSIZE
		sub	dx,bx

		mov	cx,bx
		rep movsb		;Replace top line.
		add	di,dx

		dec	bx
		dec	bx
		mov	cx,ylen
		sub	cx,2

lp:		movsb			;Save screen data.
		add	di,bx
		movsb
		add	di,dx
		loop	lp

		inc	bx
		inc	bx

		mov	cx,bx
		rep movsb		;Replace bottom line.

		ret
v_undobox	endp


;Draw a selection box (filled - saves video written over).
v_selboxf	proc	uses ds si di,saveptr:ptr byte,pos:word,xlen:word,ylen:word,color:byte
		push	ds
		pop	es
		mov	di,saveptr	;Get save buffer pointer.

		mov	ax,VSEG
		mov	ds,ax
		mov	si,pos		;Get starting position (Y*320+X).

		mov	bx,xlen
		mov	dx,XSIZE
		sub	dx,bx
		mov	al,color

		mov	cx,ylen
lp:		push	cx

		push	si
		mov	cx,bx
		rep movsb		;Save a line.
		pop	si

		push	es
		push	ds
		pop	es
		xchg	si,di
		mov	cx,bx
		rep stosb		;Draw a line.

		add	di,dx
		xchg	si,di
		pop	es

		pop	cx
		loop	lp		;Repeat for entire box.

		ret
v_selboxf	endp


;Replace a selection box from the save buffer (filled).
v_undoboxf	proc	uses ds si di,saveptr:ptr byte,pos:word,xlen:word,ylen:word
		mov	si,saveptr	;Get save buffer pointer.

		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	bx,xlen
		mov	dx,XSIZE
		sub	dx,bx

		mov	cx,ylen
lp:		push	cx

		mov	cx,bx
		rep movsb		;Replace a line.
		add	di,dx

		pop	cx
		loop	lp		;Repeat for entire box.

		ret
v_undoboxf	endp


;Display text string using 5x7 character set.
v_str		proc	uses si di,pos:word,str:ptr byte,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	si,str		;Get pointer to string.
		mov	bl,color	;Get display color.

chlp:		lodsb			;Get next character.
		or	al,al
		jz	done		;Exit if end of string.

		push	si
		push	di
		call	_v_chr		;Call subroutine to display character.
		pop	di
		add	di,6		;Point to next character position.
		pop	si
		jmp	chlp		;Display next character.

done:		ret
v_str		endp


;Display FAR text string using 5x7 character set.
v_str_f		proc	uses ds si di,pos:word,str:far ptr byte,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		lds	si,str		;Get pointer to string.
		mov	bl,color	;Get display color.

chlp:		lodsb			;Get next character.
		or	al,al
		jz	done		;Exit if end of string.

		push	ds
		mov	cx,dgroup
		mov	ds,cx
		push	si
		push	di
		call	_v_chr		;Call subroutine to display character.
		pop	di
		add	di,6		;Point to next character position.
		pop	si
		pop	ds
		jmp	chlp		;Display next character.

done:		ret
v_str_f		endp


;Display a text character using 5x7 character set.
v_chr		proc	uses si di,pos:word,chr:byte,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	al,chr		;Get character.
		mov	bl,color	;Get display color.
		call	_v_chr		;Call subroutine to display character.

		ret
v_chr		endp


;Assembly sub to display 5x7 character (DO NOT CALL FROM C!).
; ES:DI = screen position, AL = character, BL = color.
_v_chr		proc	near

		cmp	al,20h
		jb	undef		;Go if undefined character.
		cmp	al,5fh
		ja	undef		;Go if undefined character.
		sub	al,20h		;Adjust character to 0-3fh.
		jmp	cont		;Continue.
undef:		mov	al,40h		;Set to undefined character.
cont:		xor	ah,ah
		mov	cl,5*7
		mul	cl		;AX = AL * CL.
		mov	si,offset dgroup:cs5x7
		add	si,ax		;SI -> character data.

		mov	cx,7
ylp:		push	cx

		mov	cx,5
xlp:		lodsb
		or	al,al
		jz	xskip		;Skip if 0.
		mov	es:[di],bl
xskip:		inc	di
		loop	xlp		;Loop for 5 columns.

		add	di,XSIZE-5
		pop	cx
		loop	ylp		;Loop for 7 rows.

		ret
_v_chr		endp


;Display text string using 5x7 character set.
v_strf		proc	uses si di,pos:word,str:ptr byte,fcolor:byte,bcolor:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	si,str		;Get pointer to string.
		mov	bl,fcolor	;Get foreground display color.
		mov	bh,bcolor	;Get background display color.

chlp:		lodsb			;Get next character.
		or	al,al
		jz	done		;Exit if end of string.

		push	si
		push	di
		call	_v_chrf		;Call subroutine to display character.
		pop	di
		add	di,6		;Point to next character position.
		pop	si
		jmp	chlp		;Display next character.

done:		ret
v_strf		endp


;Display FAR text string using 5x7 character set.
v_strf_f	proc	uses ds si di,pos:word,str:far ptr byte,fcolor:byte,bcolor:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		lds	si,str		;Get pointer to string.
		mov	bl,fcolor	;Get foreground display color.
		mov	bh,bcolor	;Get background display color.

chlp:		lodsb			;Get next character.
		or	al,al
		jz	done		;Exit if end of string.

		push	ds
		mov	cx,dgroup
		mov	ds,cx
		push	si
		push	di
		call	_v_chrf		;Call subroutine to display character.
		pop	di
		add	di,6		;Point to next character position.
		pop	si
		pop	ds
		jmp	chlp		;Display next character.

done:		ret
v_strf_f	endp


;Display a text character using 5x7 character set.
v_chrf		proc	uses si di,pos:word,chr:byte,fcolor:byte,bcolor:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	al,chr		;Get character.
		mov	bl,fcolor	;Get foreground display color.
		mov	bh,bcolor	;Get background display color.
		call	_v_chrf		;Call subroutine to display character.

		ret
v_chrf		endp


;Assembly sub to display 5x7 character (DO NOT CALL FROM C!).
; ES:DI = screen position, AL = character, BL = FG color, BH = BG color.
_v_chrf		proc	near

		cmp	al,20h
		jb	undef		;Go if undefined character.
		cmp	al,5fh
		ja	undef		;Go if undefined character.
		sub	al,20h		;Adjust character to 0-3fh.
		jmp	cont		;Continue.
undef:		mov	al,40h		;Set to undefined character.
cont:		xor	ah,ah
		mov	cl,5*7
		mul	cl		;AX = AL * CL.
		mov	si,offset dgroup:cs5x7
		add	si,ax		;SI -> character data.

		mov	cx,7
ylp:		push	cx

		mov	cx,5
xlp:		lodsb
		or	al,al
		jz	xbackg		;Go if background (0) color.
		mov	es:[di],bl
		jmp	xcont

xbackg:		mov	es:[di],bh

xcont:		inc	di
		loop	xlp		;Loop for 5 columns.

		add	di,XSIZE-5
		pop	cx
		loop	ylp		;Loop for 7 rows.

		ret
_v_chrf		endp


;Display text string using 3x5 character set.
v_sstr		proc	uses si di,pos:word,str:ptr byte,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	si,str		;Get pointer to string.
		mov	bl,color	;Get display color.

chlp:		lodsb			;Get next character.
		or	al,al
		jz	done		;Exit if end of string.

		push	si
		call	_v_schr		;Call subroutine to display character.
		pop	si
		jmp	chlp		;Display next character.

done:		ret
v_sstr		endp


;Display a special character using 3x5 character set.
v_schr		proc	uses si di,pos:word,chr:byte,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	al,chr		;Get character.
		mov	bl,color	;Get display color.
		call	_v_schr		;Call subroutine to display character.

		ret
v_schr		endp


;Display a 2 digit hex number using special 3x5 character set.
v_shex		proc	uses si di,pos:word,val:byte,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	bl,color	;Get display color.
		mov	al,val
		shr	al,1
		shr	al,1
		shr	al,1
		shr	al,1		;Get MS nibble of value.
		call	_v_schr		;Call subroutine to display character.

		mov	al,val
		and	al,0fh		;Get LS nibble of value.
		call	_v_schr		;Call subroutine to display character.

		ret
v_shex		endp


;Assembly sub to display 3x5 character (DO NOT CALL FROM C!).
; ES:DI = screen position, AL = character, BL = color.
_v_schr		proc	near

		cmp	al,'A'
		jb	notalpha
		sub	al,55		;Translate alpha characters.

notalpha:	cmp	al,LAST3X5
		jb	cont		;Go if character ok.
		mov	al,LAST3X5	;Set to undefined character.

cont:		push	di

		mov	bh,al
		xor	ah,ah
		mov	cl,3*5
		mul	cl		;AX = AL * CL.
		mov	si,offset dgroup:cs3x5
		add	si,ax		;SI -> character data.

		mov	cx,5
ylp:		push	cx

		mov	cx,3
xlp:		lodsb
		or	al,al
		jz	xskip		;Skip if 0.
		mov	es:[di],bl
xskip:		inc	di
		loop	xlp		;Loop for 3 columns.

		add	di,XSIZE-3
		pop	cx
		loop	ylp		;Loop for 5 rows.

		pop	di
		add	di,4		;Point to next column.

		;Check for special double characters.
		mov	al,bh		;Get character.
		cmp	al,'N'-55
		jb	chkm		;Go check if 'M'.
		ja	chkup		;Go check if UP.
		mov	al,SPL3X5+1
		sub	di,3
		jmp	cont		;Go do second half of 'N'.

chkm:		cmp	al,'M'-55
		jne	chkg		;Go check if 'G'.
		mov	al,SPL3X5
		sub	di,2
		jmp	cont		;Go do second half of 'M'.

chkg:		cmp	al,'G'-55
		jne	done		;Exit if not 'G'.
		mov	al,SPL3X5+13
		sub	di,3
		jmp	cont		;Go do second half of 'G'.

chkup:		cmp	al,SPL3X5+7
		jb	chkw		;Go check if 'W'.
		ja	chkdown		;Go check if DOWN.
		mov	al,SPL3X5+8
		sub	di,2
		jmp	cont		;Go do second half of UP.

chkw:		cmp	al,'W'-55
		ja	chklr		;Go check if LEFT/RIGHT.
		jb	done		;Exit if not 'W'.
		mov	al,SPL3X5+2
		sub	di,2
		jmp	cont		;Go do second half of 'W'.

chklr:		cmp	al,SPL3X5+3
		jb	done		;Exit if below LEFT.
		jne	chkr		;Go check if RIGHT.
		mov	al,SPL3X5+4
		dec	di
		jmp	cont		;Go do second half of LEFT.

chkr:		cmp	al,SPL3X5+5
		jne	done		;Exit if not RIGHT.
		mov	al,SPL3X5+6
		dec	di
		jmp	cont		;Go do second half of RIGHT.

chkdown:	cmp	al,SPL3X5+9
		jne	chkdia		;Go check if diamond.
		mov	al,SPL3X5+10
		sub	di,2
		jmp	cont		;Go do second half of DOWN.

chkdia:		cmp	al,SPL3X5+11
		jne	chkdownb	;Go check if DOWNB or UPB.
		mov	al,SPL3X5+12
		sub	di,2
		jmp	cont		;Go do second half of DIAMOND.

chkdownb:	cmp	al,SPL3X5+14
		jne	chkupb		;Go check if DOWNB.
		mov	al,SPL3X5+15
		sub	di,2
		jmp	cont		;Go do second half of DOWNB.

chkupb:		cmp	al,SPL3X5+16
		jne	done		;Exit if not UPB.
		mov	al,SPL3X5+17
		sub	di,2
		jmp	cont		;Go do second half of UPB.

done:		ret
_v_schr		endp


;Display Nintendo character set in n-high mode.
cs_display	proc	uses ds si di,pos:word,csptr:far ptr byte,color:byte,nhigh:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	dl,color	;Get palette offset (dword aligned).
		lds	si,csptr	;DS:SI -> character set data.

		mov	dh,nhigh	;DH = n.

		mov	cx,8
mainlp:		push	cx
		push	dx
		mov	dh,nhigh
		shl	dh,1
		shl	dh,1
		shl	dh,1
		shl	dh,1
		sub	dh,8		;DH = n * 16 - 8;

		mov	cx,32
rowlp:		push	cx
		push	di

		mov	cx,8
chrlp:		push	cx
		mov	bl,[si]		;BL = byte from first bit plane (LS).
		mov	ah,[si+8]	;AH = byte from second bit plane (MS).
		inc	si

		mov	cx,8
scanlp:		xor	al,al		;AL = 0.
		rol	ax,1		;Get MS bit in AL.
		sal	bl,1
		rcl	al,1		;Get LS bit in AL.
		or	al,dl		;Add palette offset.
		stosb			;Store byte on screen.
		loop	scanlp		;Loop for 8 pixels.

		add	di,XSIZE-8	;Next line.
		pop	cx
		loop	chrlp		;Loop for 8 scan lines.

		mov	al,dh
		xor	ah,ah
		add	si,ax		;Next character.
		pop	di
		add	di,8		;Next character.
		pop	cx
		loop	rowlp		;Loop for 32 characters.

		mov	al,nhigh
		xor	ah,ah		;AX = n.
		pop	dx
		dec	dh		;Decrement n-high counter.
		jnz	acont		;Continue if not zero.

		mov	dh,al		;Reset counter.
		dec	al
		shl	ax,1
		shl	ax,1
		shl	ax,1
		shl	ax,1		;AX = (n - 1) * 16
		sub	si,ax		;Adjust SI.
		jmp	adone		;Continue.

acont:		shl	ax,1
		shl	ax,1
		shl	ax,1
		shl	ax,1
		shl	ax,1
		shl	ax,1
		shl	ax,1
		shl	ax,1
		shl	ax,1
		sub	ax,16		;AX = n * 32 * 16 - 16
		sub	si,ax

adone:		add	di,XSIZE*8-256
		pop	cx
		loop	mainlp		;Loop for 8 rows of characters.

		ret
cs_display	endp


;Display a single character from Nintendo character set.
cs_chr		proc	uses ds si di,pos:word,csptr:far ptr byte,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	dl,color	;Get palette offset (dword aligned).
		lds	si,csptr	;DS:SI -> character set data.

		mov	cx,8
chrlp:		push	cx
		mov	bl,[si]		;BL = byte from first bit plane (LS).
		mov	ah,[si+8]	;AH = byte from second bit plane (MS).
		inc	si

		mov	cx,8
scanlp:		xor	al,al		;AL = 0.
		rol	ax,1		;Get MS bit in AL.
		sal	bl,1
		rcl	al,1		;Get LS bit in AL.
		or	al,dl		;Add palette offset.
		stosb			;Store byte on screen.
		loop	scanlp		;Loop for 8 pixels.

		add	di,XSIZE-8	;Next line.
		pop	cx
		loop	chrlp		;Loop for 8 scan lines.

		ret
cs_chr		endp


;Display a single character from character set, flipped vertically.
cs_chr_fv	proc	uses ds si di,pos:word,csptr:far ptr byte,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	dl,color	;Get palette offset (dword aligned).
		lds	si,csptr	;DS:SI -> character set data.
		add	si,7

		mov	cx,8
chrlp:		push	cx
		mov	bl,[si]		;BL = byte from first bit plane (LS).
		mov	ah,[si+8]	;AH = byte from second bit plane (MS).
		dec	si

		mov	cx,8
scanlp:		xor	al,al		;AL = 0.
		rol	ax,1		;Get MS bit in AL.
		sal	bl,1
		rcl	al,1		;Get LS bit in AL.
		or	al,dl		;Add palette offset.
		stosb			;Store byte on screen.
		loop	scanlp		;Loop for 8 pixels.

		add	di,XSIZE-8	;Next line.
		pop	cx
		loop	chrlp		;Loop for 8 scan lines.

		ret
cs_chr_fv	endp


;Display a single character from character set, flipped horizontally.
cs_chr_fh	proc	uses ds si di,pos:word,csptr:far ptr byte,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	dl,color	;Get palette offset (dword aligned).
		lds	si,csptr	;DS:SI -> character set data.

		mov	cx,8
chrlp:		push	cx
		mov	bl,[si]		;BL = byte from first bit plane (LS).
		mov	ah,[si+8]	;AH = byte from second bit plane (MS).
		inc	si

		mov	cx,8
scanlp:		xor	al,al		;AL = 0.
		sar	ah,1
		rcl	al,1		;Get MS bit in AL.
		sar	bl,1
		rcl	al,1		;Get LS bit in AL.
		or	al,dl		;Add palette offset.
		stosb			;Store byte on screen.
		loop	scanlp		;Loop for 8 pixels.

		add	di,XSIZE-8	;Next line.
		pop	cx
		loop	chrlp		;Loop for 8 scan lines.

		ret
cs_chr_fh	endp


;Display a single character from character set, flipped vert. & hori.
cs_chr_fvh	proc	uses ds si di,pos:word,csptr:far ptr byte,color:byte
		mov	ax,VSEG
		mov	es,ax
		mov	di,pos		;Get starting position (Y*320+X).

		mov	dl,color	;Get palette offset (dword aligned).
		lds	si,csptr	;DS:SI -> character set data.
		add	si,7

		mov	cx,8
chrlp:		push	cx
		mov	bl,[si]		;BL = byte from first bit plane (LS).
		mov	ah,[si+8]	;AH = byte from second bit plane (MS).
		dec	si

		mov	cx,8
scanlp:		xor	al,al		;AL = 0.
		sar	ah,1
		rcl	al,1		;Get MS bit in AL.
		sar	bl,1
		rcl	al,1		;Get LS bit in AL.
		or	al,dl		;Add palette offset.
		stosb			;Store byte on screen.
		loop	scanlp		;Loop for 8 pixels.

		add	di,XSIZE-8	;Next line.
		pop	cx
		loop	chrlp		;Loop for 8 scan lines.

		ret
cs_chr_fvh	endp


;Fill a Nintendo character set with a single character.
cs_fill		proc	uses ds si di,csptr:far ptr byte,chrptr:ptr byte

		mov	dx,chrptr	;DS:DX -> character data.
		les	di,csptr	;ES:DI -> character set.
		mov	bx,8

		mov	cx,512
mainlp:		push	cx

		mov	si,dx
		mov	cx,bx
		rep movsw		;Put character.

		pop	cx
		loop	mainlp		;Loop for 256 characters.

		ret
cs_fill		endp


;Routine to check if key is waiting.
ifkey		proc	uses si di
		mov	ah,1
		int	16h
		jnz	gotkey
		xor	ax,ax
		ret
gotkey:		mov	ax,-1
		ret
ifkey		endp


;Routine to get key char & scan code.
getkey		proc	uses si di,scanp:ptr byte
		push	bp
		xor	ah,ah
		int	16h
		pop	bp
		mov	bx,scanp
		mov	[bx],ah
		xor	ah,ah
		ret
getkey		endp


;Routine to preview key char & scan code WITHOUT reading key.
prekey		proc	uses si di,scanp:ptr byte
		push	bp
		mov	ah,1
		int	16h
		pop	bp
		jz	nopkey
		mov	bx,scanp
		mov	[bx],ah
		xor	ah,ah		;AL has scan code.
		ret
nopkey:		xor	ax,ax
		ret
prekey		endp


;Emit a 2000Hz beep.
beep		proc
		mov	dx,597		;2000 Hz.
		mov	al,0b6h
		out	43h,al		;Program new frequency.
		mov	al,dl
		out	42h,al
		mov	al,dh
		out	42h,al
		in	al,61h
		or	al,3
		out	61h,al		;Turn on sound.
		mov	cx,8000
bwait:		nop
		nop
		loop	bwait
		in	al,61h
		and	al,0fch
		out	61h,al		;Turn off sound.
		ret
beep		endp


;Special version of C's movedata() call that handles overlapping data.
;NOTE: if segments are different, data is assumed not to overlap!!
smovedata	proc	uses ds si di,srcseg:word,srcoff:word,destseg:word,destoff:word,len:word

		mov	ax,srcseg
		mov	ds,ax
		mov	si,srcoff
		mov	bx,destseg
		mov	es,bx
		mov	di,destoff

		cmp	ax,bx
		jne	cont		;Continue if different segments.

		cmp	si,di
		jb	reverse		;Do reverse move if overlap exists.

cont:		mov	cx,len
		rep movsb		;Move data.
		jmp	done

reverse:	mov	cx,len
		add	si,cx
		dec	si
		add	di,cx
		dec	di
		std
		rep movsb
		cld

done:		ret
smovedata	endp


;FAR PTR version of C's memset() call.
memset_f	proc	uses di,dest:far ptr byte,val:byte,len:word

		les	di,dest		;ES:DI points to destination.
		mov	cx,len		;CX = length.
		mov	al,val		;AL = data value.
		rep stosb

		ret
memset_f	endp


;FAR PTR version of C's strcmp() call (parm2 only, parm1 is NEAR).
strcmp_nf	proc	uses si di,src:ptr byte,dest:far ptr byte

		mov	si,src
		les	di,dest
		mov	cx,-1
		xor	ax,ax
		repnz scasb

		not	cx
		sub	di,cx
		repz cmpsb

		je	done
		sbb	ax,ax
		sbb	ax,-1

done:		ret
strcmp_nf	endp


;FAR PTR version of C's strcmp() call (both parms are FAR)
strcmp_ff	proc	uses ds si di,src:far ptr byte,dest:far ptr byte

		lds	si,src
		les	di,dest
		mov	cx,-1
		xor	ax,ax
		repnz scasb

		not	cx
		sub	di,cx
		repz cmpsb

		je	done
		sbb	ax,ax
		sbb	ax,-1

done:		ret
strcmp_ff	endp


;Initialize mouse.
initmouse	proc	uses si di

		xor	ax,ax
		mov	es,ax
		mov	di,33h*4
		mov	ax,es:[di]
		or	ax,es:[di+2]
		jz	done		;Go if mouse not installed.

		xor	ax,ax
		int	33h		;Initialize mouse.

		cmp	bx,2
		jne	done		;Skip if not 2 button mouse.
		mov	ms_driver,-1	;Assume Microsoft driver if 2 buttons.

done:		ret
initmouse	endp


;Show mouse cursor.
showmouse	proc	uses si di
		mov	ax,1
		int	33h		;Show mouse cursor.
		ret
showmouse	endp


;Hide mouse cursor.
hidemouse	proc	uses si di
		mov	ax,2
		int	33h		;Hide mouse cursor.
		ret
hidemouse	endp


;Get mouse position.
getmouse	proc	uses si di,stat:ptr byte,xpos:ptr word,ypos:ptr word

		mov	ax,3
		int	33h		;Get mouse position.
		mov	al,bl
		mov	bx,stat
		mov	[bx],al		;Return button status.
		mov	bx,xpos
		mov	[bx],cx		;Return X position.
		mov	bx,ypos
		mov	[bx],dx		;Return Y position.
		xor	ax,ax

		ret
getmouse	endp


;Set mouse position.
setmouse	proc	uses si di,xpos:word,ypos:word

		mov	cx,xpos		;Get X position.
		mov	dx,ypos		;Get Y position.
		mov	ax,4
		int	33h		;Set mouse position.

		ret
setmouse	endp


;Set mouse X limits.
xlimitmouse	proc	uses si di,xmin:word,xmax:word

		mov	cx,xmin		;Get X minimum.
		mov	dx,xmax		;Get X maximum.
		mov	ax,7
		int	33h		;Set mouse X limits.

		ret
xlimitmouse	endp


;Set mouse Y limits.
ylimitmouse	proc	uses si di,ymin:word,ymax:word

		mov	cx,ymin		;Get Y minimum.
		mov	dx,ymax		;Get Y maximum.
		mov	ax,8
		int	33h		;Set mouse Y limits.

		ret
ylimitmouse	endp


;Set mouse pointer graphics.
shapemouse	proc	uses si di,pdata:word

		mov	ax,ds
		mov	es,ax
		mov	bx,pdata
		mov	al,[bx]
		xor	ah,ah
		cmp	ms_driver,0
		jz	cont		;Continue if not Microsoft driver.
		shl	al,1		;Double X to correct for bug!
cont:		mov	cl,[bx+1]	;CX = Y hot spot.
		xor	ch,ch
		mov	dx,bx
		add	dx,2		;ES:DX -> graphics data.
		mov	bx,ax		;BX = X hot spot.
		mov	ax,9
		int	33h		;Set mouse pointer graphics.

		ret
shapemouse	endp


;Set user-defined event handler for mouse.
handlemouse	proc	uses si di

		mov	cx,1fh		;Set call mask.
		mov	ax,cs
		mov	es,ax
		mov	dx,offset mouseevent	;Set pointer to event handler.
		mov	ax,0ch
		int	33h		;Set user-defined event hander.

		ret
handlemouse	endp


;Process mouse event (INTERRUPT driven!).
mouseevent	proc	far
		push	ds

		mov	bh,al
		mov	ax,dgroup
		mov	ds,ax		;Load DS with DGROUP.

		mov	ax,mq_head	;Get mq_head pointer.
		inc	ax		;Increment queue head pointer.
		cmp	ax,MQ_SIZE-1
		jbe	skip		;Go if no wrap.
		xor	ax,ax		;Wrap to 0.

skip:		cmp	ax,mq_tail
		jne	notfull		;Go if queue is not full.

		shl	ax,1
		mov	si,ax
		shl	ax,1
		add	si,ax		;SI = mq_head * 6

		mov	al,mq[si]
		or	al,bh
		mov	mq[si],al	;Or event byte to one already there.
		jmp	cont		;Continue.

notfull:	mov	mq_head,ax	;Set new mq_head value.

		shl	ax,1
		mov	si,ax
		shl	ax,1
		add	si,ax		;SI = mq_head * 6

		mov	mq[si],bh	;Store event byte.

cont:		mov	mq[si+1],bl	;Store state byte.
		shr	cx,1
		mov	word ptr mq[si+2],cx	;Store xpos/2 word.
		mov	word ptr mq[si+4],dx	;Store ypos word.

		pop	ds
		ret
mouseevent	endp


;Flush mouse queue.
flushmouse	proc

		cli
		mov	mq_head,0
		mov	mq_tail,0
		sti

		ret
flushmouse	endp


;Check for mouse input (read event from queue & process it)
checkmouse	proc

		mov	ax,mq_tail
		cmp	ax,mq_head
		je	done		;Exit if queue is empty.

		inc	ax		;Increment queue tail pointer.
		cmp	ax,MQ_SIZE-1
		jbe	skip		;Go if no wrap.
		xor	ax,ax		;Wrap to 0.

skip:		mov	mq_tail,ax	;Store new mq_tail value.

		shl	ax,1
		mov	bx,ax
		shl	ax,1
		add	bx,ax		;BX = mq_head * 6

		mov	ax,word ptr mq[bx+4]
		push	ax		;Push ypos word on stack.
		mov	ax,word ptr mq[bx+2]
		push	ax		;Push xpos word on stack.
		mov	al,mq[bx+1]
		xor	ah,ah
		push	ax		;Push state byte on stack.
		mov	al,mq[bx]
		push	ax		;Push event byte on stack.
		call	procmouse	;Process the mouse event.
		add	sp,8

done:		ret
checkmouse	endp


;Read from a file into a type FAR buffer.
readfar		proc	uses si di,fh:word,buf:far ptr byte,len:word

		mov	bx,fh		;BX = file handle.
		mov	cx,len		;CX = length.
		push	ds
		lds	dx,buf		;DS:DX -> data buffer.
		mov	ah,3fh		;Read File.
		int	21h
		pop	ds
		jnc	done		;Exit if no errors.

		mov	errno,ax	;Save error number.
		mov	ax,-1		;Return error.

done:		ret
readfar		endp


;Write into a file from a type FAR buffer.
writefar	proc	uses si di,fh:word,buf:far ptr byte,len:word

		mov	bx,fh		;BX = file handle.
		mov	cx,len		;CX = length.
		push	ds
		lds	dx,buf		;DS:DX -> data buffer.
		mov	ah,40h		;Read File.
		int	21h
		pop	ds
		jnc	done		;Exit if no errors.

		mov	errno,ax	;Save error number.
		mov	ax,-1		;Return error.

done:		ret
writefar	endp


;Vertical retrace interrupt handler.
videoint	proc	far

		push	ax
		push	dx
		push	ds
		mov	ax,dgroup
		mov	ds,ax		;Set DS register.

		mov	dx,3c2h
		in	al,dx		;Read Input Status Register Zero.
		test	al,80h		;Check vertical interrupt bit.
		jnz	cont		;Go if set.
		jmp	abort		;Exit if not vertical retrace.

cont:		push	di
		push	es

		pop	es
		pop	di

abort:		pop	ds
		pop	dx
		pop	ax

		db	0eah		;JMP FAR continue.
cont0A::	dw	0,0

videoint	endp


;Take over vertical retrace interrupt vector (HARDWARE INT 2).
intvideo 	proc	uses si di

		mov	ax,350ah
		int	21h
		mov	cs:word ptr cont0a,bx
		mov	cs:word ptr cont0a+2,es

		push	ds
		mov	ax,cs
		mov	ds,ax
		mov	dx,offset videoint
		mov	ax,250ah
		int	21h
		pop	ds

		mov	al,21h		;Get interrupt controller status.
		mov	ic_stat,al	;Save it.
		and	al,11111011b	;Enable IRQ2.
		out	21h,al

		mov	dx,3d4h
		mov	al,11h		;Vertical Retrace End register.
		out	dx,al
		inc	dx
		in	al,dx		;Read VRE register.
		mov	ah,al
		and	ah,11001111b	;Enable & clear IRQ2.
		dec	dx
		mov	al,11h
		out	dx,al
		inc	dx
		mov	al,ah
		out	dx,al
		or	al,10000b	;Re-enable interrupt.
		out	dx,al

		ret
intvideo	endp


;Fixup vertical retrace interrupt vector (HARDWARE INT 2).
fixvideo	proc	uses si di

		mov	al,ic_stat
		out	21h,al		;Restore interrupt controller status.

		mov	ah,0fh
		int	10h		;Get video mode.
		and	ax,7fh
		int	10h		;Set video mode (clear IRQ2).

		push	ds
		lds	dx,cs:dword ptr cont0a
		mov	ax,250ah
		int	21h
		pop	ds

		mov	ah,0fh
		int	10h		;Get video mode.
		and	ax,7fh
		int	10h		;Set video mode (clear IRQ2).

		ret
fixvideo	endp


;Ctrl-Break key routine.
execbrk		proc	far
		sti
		push	ax
		push	ds
		mov	ax,dgroup
		mov	ds,ax
		mov	brkkey,-1
		pop	ds
		pop	ax
		iret
execbrk		endp


;Ctrl-C key routine.
execbrk2	proc	far
		iret
execbrk2	endp


;Take over break key vectors (1bh & 23h).
intbrk	 	proc	uses si di

		mov	al,1bh
		mov	ah,35h
		int	21h
		mov	word ptr vec1b,bx
		mov	word ptr vec1b+2,es

		push	ds
		mov	ax,cs
		mov	ds,ax
		mov	dx,offset execbrk
		mov	al,1bh
		mov	ah,25h
		int	21h
		pop	ds

		mov	al,23h
		mov	ah,35h
		int	21h
		mov	word ptr vec23,bx
		mov	word ptr vec23+2,es

		push	ds
		mov	ax,cs
		mov	ds,ax
		mov	dx,offset execbrk2
		mov	al,23h
		mov	ah,25h
		int	21h
		pop	ds

		xor	al,al
		mov	ah,33h
		int	21h
		mov	brkstat,dl
		xor	dl,dl
		mov	al,1
		mov	ah,33h
		int	21h

		ret
intbrk	 	endp


;Fixup break key vectors (1bh & 23h).
fixbrk		proc	uses si di

		mov	dl,brkstat
		mov	al,1
		mov	ah,33h
		int	21h

		push	ds
		lds	dx,vec1b
		mov	al,1bh
		mov	ah,25h
		int	21h
		pop	ds

		push	ds
		lds	dx,vec23
		mov	al,23h
		mov	ah,25h
		int	21h
		pop	ds

		ret
fixbrk		endp


;Print screen routine.
execpscr	proc	far
		iret
execpscr	endp


;Take over print screen vector (05h).
intpscr 	proc	uses si di

		mov	al,5
		mov	ah,35h
		int	21h
		mov	word ptr vec05,bx
		mov	word ptr vec05+2,es

		push	ds
		mov	ax,cs
		mov	ds,ax
		mov	dx,offset execpscr
		mov	al,5
		mov	ah,25h
		int	21h
		pop	ds

		ret
intpscr		endp


;Fixup print screen vector (05h).
fixpscr		proc	uses si di

		push	ds
		lds	dx,vec05
		mov	al,5
		mov	ah,25h
		int	21h
		pop	ds

		ret
fixpscr		endp


		end